package com.qf.web.servlet;

import com.qf.pojo.Goods;
import com.qf.pojo.PageBean;
import com.qf.service.GoodsService;
import com.qf.service.impl.GoodsServiceImpl;
import com.qf.utils.StrUtils;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/goodsservlet")
public class GoodsServlet extends BaseServlet {
    GoodsService goodsService = new GoodsServiceImpl();

    public String getGoodsById(HttpServletRequest request, HttpServletResponse response) throws Exception{
        int id = Integer.parseInt(request.getParameter("id")) ;
        Goods goods= goodsService.findById(id);
        request.setAttribute("goods",goods);
        return "forward:/goodsDetail.jsp";
    }
    public String getGoodsListByTypeId(HttpServletRequest request, HttpServletResponse response) throws Exception{
        //获取分类Id

        int typeId = Integer.parseInt(request.getParameter("typeId"));
        String pageNumStr = request.getParameter("PageNum");
        String pageSizeStr = request.getParameter("pageSize");
        int pageNum =1;
        int pageSize=2;
        if (StrUtils.isNotEmpty(pageNumStr)) {
            pageNum = Integer.parseInt(pageNumStr);
        }



        if (StrUtils.isNotEmpty(pageSizeStr)) {
            pageSize = Integer.parseInt(pageSizeStr);
        }
        PageBean pageBean = goodsService.findByPage(typeId,pageNum,pageSize);
        request.setAttribute("pageBean",pageBean);
        request.setAttribute("typeId",typeId);
        return "forward:/goodsList.jsp";


    }

}
